import 'package:flutter/material.dart';

/// Created by XieXin on 2020/12/16.
/// TabBar颜色指示器
class XColorTabIndicator extends Decoration {
  const XColorTabIndicator(this.color);

  ///选中的颜色
  final Color color;

  @override
  ColorPainter createBoxPainter([VoidCallback? onChanged]) {
    return ColorPainter(this, onChanged);
  }
}

class ColorPainter extends BoxPainter {
  ColorPainter(this.decoration, VoidCallback? onChanged) : super(onChanged);

  final XColorTabIndicator decoration;

  @override
  void paint(Canvas canvas, Offset offset, ImageConfiguration configuration) {
    final Rect rect = offset & configuration.size!;
    final Paint paint = Paint();
    paint.color = decoration.color;
    canvas.drawRect(rect, paint);
  }
}
